package com.zut.dao;

import com.zut.pojo.Product;
import com.zut.pojo.Type;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ProductDao {
    @Select("select * from `type` where status=1")
    List<Type> selectAllProductType();


    // 发布项目
    @Insert("insert into product(user_id,service_name,service_phone,type_id,title,image_url,goal,city_id,money,days,video,story,provideReturns,aboutme,start_time,end_time) values (#{userId},#{serviceName},#{servicePhone},#{typeId},#{title},#{imageUrl},#{goal},#{cityId},#{money},#{days},#{video},#{story},#{providereturns},#{aboutme},#{startTime},#{endTime})")
    int addProduct(Product product);

    // 根据product 查出id 使其与repay记录进行关联起来
    @Select("select * from product where user_id=#{userId} and service_name=#{serviceName} and service_phone=#{servicePhone} and type_id=#{typeId} and title=#{title} and image_url=#{imageUrl} and goal=#{goal} and money=#{money} and days=#{days} and video=#{video} and story=#{story} and provideReturns=#{providereturns} and aboutme=#{aboutme}")
    Product selectIdByProduct(Product product);

    // 查询所有已发布的项目
    List<Product> selectAllProjects();

    // 通过id查询type
    @Select("select * from `type` where id=#{typeId}")
    Type selectTypeById(@Param("typeId") Integer typeId);

    // 查询所有类型
    @Select("select * from `type`")
    List<Type> selectAllType();

    // 根据id查项目
//    @Select("select * from product where id=#{id}")
    Product selectProductById(@Param("id") Integer id);
}
